package fs

import (
	"embed"
	"fmt"
	"io/fs"
	"strings"
)

type EmbedFS struct {
	fs embed.FS
	rootDir string
}

type File struct{}
type FileInfo struct{}

func NewEmbedFS(embedFs embed.FS,rootDirs ...string) *EmbedFS {
	rootDir:="html"
	if len(rootDirs)>0 {
		rootDir = rootDirs[0]
	}
	return &EmbedFS{
		fs:embedFs,
		rootDir: rootDir,
	}
}

func (f *EmbedFS) Open(name string)(of fs.File,e error)  {
	if strings.Index(name,"/")==0 {
		name = name[1:]
	}
	name = fmt.Sprintf("%s/%s",f.rootDir,name)
	return f.fs.Open(name)
}